//
//  DetailseView.m
//  大轮胎
//
//  Created by 曹亮 on 2017/3/29.
//  Copyright © 2017年 zyc. All rights reserved.
//

#import "DetailseView.h"
#import <SDAutoLayout.h>
@implementation DetailseView
//UI界面添加到视图

-(instancetype)initWithFrame:(CGRect)frame

{
    if (self=[super initWithFrame:frame]) {
        
        
        self.backgroundColor=[UIColor whiteColor];
        [self addSubview:self.top];
        [self addSubview:self.imageV];
        [self addSubview:self.nameLabel];
        [self addSubview:self.seamented];
        [self addSubview:self.preiceLabel];
        [self addSubview:self.preice_Label];
        [self addSubview:self.pcs];
        [self addSubview:self.botton];
        [self addSubview:self.price];
        
        //适配位置
        
        self.imageV.sd_layout.topSpaceToView(self,64).leftSpaceToView(self,0).rightSpaceToView(self,0).heightRatioToView(self,0.33);
        
        self.nameLabel.sd_layout.leftSpaceToView(self,15).rightSpaceToView(self,15).topSpaceToView(self.imageV,40).heightIs(50);
        
        self.seamented.sd_layout.topSpaceToView(self.imageV,3).leftSpaceToView(self,8).rightSpaceToView(self,8).heightRatioToView(self,0.05);
        
        
        self.preiceLabel.sd_layout.leftSpaceToView(self,15).widthIs(80).topSpaceToView(self.nameLabel,7).heightIs(15);
        
        self.preice_Label.sd_layout.leftSpaceToView(self.preiceLabel,5).rightSpaceToView(self,15).heightIs(15).topSpaceToView(self.nameLabel,7);
        self.pcs.sd_layout.topSpaceToView(self.preice_Label,30).leftSpaceToView(self,15).widthIs(100).heightIs(15);
        
        self.price.sd_layout.topSpaceToView(self.preice_Label,30).rightSpaceToView(self,35).widthIs(50).heightIs(15);
        
        self.top.sd_layout.heightIs(0.5).leftSpaceToView(self,0).rightSpaceToView
        (self,0).topSpaceToView(self.preice_Label,15);
        
        self.botton.sd_layout.heightIs(0.5).leftSpaceToView(self,15).rightSpaceToView
        (self,15).topSpaceToView(self.pcs,15);
        

    }

    return self;
}
//图片视图
-(UIImageView*)imageV
{
    if (!_imageV) {
        _imageV=[[UIImageView alloc]init];
    }
    
    return _imageV;
}

//namelabel
-(UILabel*)nameLabel
{
    if (!_nameLabel) {
        _nameLabel=[[UILabel alloc]init];
        _nameLabel.font=[UIFont systemFontOfSize:18];
        [_nameLabel setTextColor:[UIColor blackColor]];
        _nameLabel.numberOfLines=0;
        
    }
    
    return _nameLabel;
}
//分段控制器
-(UISegmentedControl*)seamented
{
    if (!_seamented) {
        _seamented=[[UISegmentedControl alloc]initWithItems:@[@"分享",@"收藏",@"详细",@"评论"]];
        _seamented.segmentedControlStyle=UISegmentedControlStyleBordered;
        
        _seamented.tintColor=[UIColor colorWithRed:0.293 green:0.998 blue:0.127 alpha:1.000];
       
        _seamented.backgroundColor=[UIColor orangeColor];
        //设置无边框分段控制器
        
        //设置test控件的颜色为透明
        _seamented.tintColor = [UIColor clearColor];
        //定义选中状态的样式selected，类型为字典
        NSDictionary *selected = @{NSFontAttributeName:[UIFont systemFontOfSize:20],
                                   NSForegroundColorAttributeName:[UIColor whiteColor]};
        //定义未选中状态下的样式normal，类型为字典
        NSDictionary *normal = @{NSFontAttributeName:[UIFont systemFontOfSize:15],
                                 NSForegroundColorAttributeName:[UIColor blackColor]};
        
        /*
         NSFontAttributeName -> 系统宏定义的特殊键，用来给格式字典中的字体赋值
         NSForegroundColorAttributeName -> 系统宏定义的特殊键，用来给格式字典中的字体颜色赋值
         */
        
        //通过setTitleTextAttributes: forState: 方法来给test控件设置文字内容的格式
        [_seamented setTitleTextAttributes:normal forState:UIControlStateNormal];
        [_seamented setTitleTextAttributes:selected forState:UIControlStateSelected];
        
        //设置test初始状态下的选中下标
        _seamented.selectedSegmentIndex = 0;
        
        
    }
    return _seamented;
}

-(UILabel*)preiceLabel{

    if (!_preiceLabel) {

        _preiceLabel=[[UILabel alloc]init];
        
        _preiceLabel.textColor=[UIColor redColor];
        
        _preiceLabel.font=[UIFont systemFontOfSize:18];
        
    }
    return _preiceLabel;
}
//降价之前的价格

-(UILabel*)preice_Label
{
    if (!_preice_Label) {
        
        _preice_Label=[[UILabel alloc]init];
       

        _preice_Label.font=[UIFont systemFontOfSize:18];
        
        _preice_Label.textColor=[UIColor lightGrayColor];
    }
    
    return _preice_Label;
}


-(UILabel*)pcs
{
    if (!_pcs) {
        _pcs=[[UILabel alloc]init];
        
        _pcs.text=@"起批量(pcs)";
        
        _pcs.font=[UIFont systemFontOfSize:16];
    }
    
    return _pcs;
}
-(UILabel*)top
{
    if (!_top) {
        _top=[[UILabel alloc]init];
        _top.backgroundColor=[UIColor lightGrayColor];
        
    }
    return _top;
}
-(UILabel*)botton
{
    if (!_botton) {
        _botton=[[UILabel alloc]init];
        
        _botton.backgroundColor=[UIColor lightGrayColor];
    }
    
    return _botton;
}
-(UILabel*)price
{
    if (!_price) {
        _price=[[UILabel alloc]init];
        
        _price.text=@"价格";
        _price.font=[UIFont systemFontOfSize:16];
    }
    
    return _price;
}
//传递图片信息
-(void)setImgStr:(NSString *)imgStr
{
    _imgStr = imgStr;
    
    [self.imageV sd_setImageWithURL:[NSURL URLWithString:imgStr] placeholderImage:[UIImage imageNamed:@"2"]];
    
}


//传递label信息
-(void)setLabelStr:(NSString *)labelStr
{
    
    _labelStr=labelStr;
    
    self.nameLabel.text=labelStr;
}

//价钱
-(void)setPriceStr:(NSString *)priceStr
{

    _priceStr=priceStr;
    
    self.preiceLabel.text=[NSString stringWithFormat:@"¥ %@",priceStr];
}

//降价之前的数据
-(void)setPrice_Str:(NSString *)price_Str
{
    _price_Str=price_Str;
    
    NSMutableAttributedString *newPrice = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"￥%@",price_Str]];
            [newPrice addAttribute:NSStrikethroughStyleAttributeName value:@(NSUnderlinePatternSolid | NSUnderlineStyleSingle) range:NSMakeRange(0, newPrice.length)];
            self.preice_Label.attributedText = newPrice;


    
    
}
@end
